<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        .el-page-header__content{
            color: white;
            font-weight: bold;
        }
    </style>
    <title>Title</title>
</head>
<body>
<div id="app">
    <el-page-header style="background-color: #008000;
            color: white;line-height: 60px" content="添加商品">
    </el-page-header>
    <el-card style="width: 600px;height: 700px;margin: 0 auto">
        <el-form label-width="80px">
            <el-form-item label="商品标题">
                <el-input type="text" v-model="zc.title"></el-input>
            </el-form-item>
            <el-form-item label="商品价格">
                <el-input type="text" v-model="zc.price"></el-input>
            </el-form-item>
            <el-form-item label="商品原价">
                <el-input type="text" v-model="zc.old_price"></el-input>
            </el-form-item>
            <el-form-item label="商品库存">
                <el-input type="text" v-model="zc.sku"></el-input>
            </el-form-item>
            <el-form-item label="商品类别">
                <el-select v-model="zc.category_id">
                    <el-option v-for="c in categoryArr"
                               :label="c.name" :value="c.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="商品图片">
                <el-upload
                        name="pic"
                        limit="1"
                        list-type="picture-card"
                        :on-success="handleSuccess"
                        :on-preview="handlePictureCardPreview"
                        :on-remove="handleRemove">
                    <i></i>
                </el-upload>
                <el-dialog visible.sync="dialogVisible">
                    <img width="100%" :src="dialogImageUrl" alt="">
                </el-dialog>
            </el-form-item>
            <el-form-item>
                <el-button type="success" @click="insert()">添加商品</el-button>
            </el-form-item>
        </el-form>
    </el-card>


</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function() {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                zc:{
                    title: "",
                    price: "",
                    old_price: "",
                    sale_count: "",
                    sku: "",
                    category_id: "",
                    url: ""
                },
                categoryArr:[]
            }
        },
        methods:{
            insert(){
                if (v.p.url=="") {
                    v.$message.error("请选择上传的图片!");
                    return;
                }


            },
            handleSuccess(response,file,fileList){
                v.p.url = response;
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
                axios.get("/remove?url="+ v.p.url).then(function () {
                    v.$message("服务器图片删除完成");
                    v.p.url="";
                })
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            }
        }

    })
</script>
</html>